<template>
  <Upload
    :accept="uploadConfig.accept"
    :max-size="uploadConfig.maxSize"
    :name="uploadConfig.name"
    :with-credentials='true'
    :on-success="uploadSuccess"
    :action="uploadConfig.action">
    <Button type="ghost" icon="ios-cloud-upload-outline">上传图片</Button>
  </Upload>
</template>

<script>
  export default {
    name: "ImgUpload",
    data() {
      return {
        uploadConfig: {
          action: this.baseUrl+'/upload',
          name: 'file',
          accept: 'image/*',
          maxSize: 2018 //最大文件大小限制
        }
      }
    },
    methods: {
      uploadSuccess(response, file) {  //文件上传成功的时候
        if (response.code != 0) {
          let data = response.data;
          this.$emit('onSuccess', data.absoluteUrl);
        } else {
          this.$emit('onError', response.msg);
          this.$Message.error(response.msg);
        }
      }
    }
  }
</script>

<style scoped>

</style>
